package com.bobo.mapper;

import com.bobo.entity.Vegetable;
import com.github.pagehelper.Page;
import com.bobo.annotation.AutoFill;
import com.bobo.dto.VegetablePageQueryDTO;
import com.bobo.enumeration.OperationType;
import com.bobo.vo.VegetableVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface VegetableMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from vegetable where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);
    @AutoFill(value= OperationType.INSERT)
    void insert(Vegetable vegetable);

    /**
     * 菜品分页查询
     * @param vegetablePageQueryDTO
     * @return
     */
    Page<VegetableVO> pageQuery(VegetablePageQueryDTO vegetablePageQueryDTO);

    /**
     * 根据主键查询菜品
     * @param id
     * @return
     */
    @Select("select * from vegetable where id = #{id}")
    Vegetable getById(Long id);

    /**
     * 根据主键删除菜品数据
     * @param id
     */
    @Delete("delete from vegetable where id=#{id}")
    void deleteById(Long id);

    /**
     * 根据菜品id集合批量删除菜品
     * @param ids
     */
    void deleteByIds(List<Long> ids);

    /**
     * 根据id动态修改菜品数据
     * @param vegetable
     */
    @AutoFill(value= OperationType.UPDATE)
    void update(Vegetable vegetable);

    /**
     * 动态查询菜品
     * @param vegetable
     * @return
     */
    List<Vegetable> list(Vegetable vegetable);

    /**
     * 根据套餐id查询菜品
     * @param id
     * @return
     */
    @Select("select a.* from vegetable a left join setmeal_dish b on a.id=b.dish_id where b.setmeal_id = #{setmealId}")
    List<Vegetable> getBysetmealId(Long id);
    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
